﻿﻿
<title>${registrationNO}-视频回放</title>
   <%@ include file="videoHead.jsp"%>
</head>
<body class="videoHd" onUnload="stopRealPlay()" >
<div class="videoPage">
	<div class="video-chart">
		<div class="video" style="border:double;background: url(${appCtx}resources/images/video/bg.jpg) #ededed no-repeat 50% 0;">
			<object id="IScanClientOCXCtrl" style="z-index:-100; width:100%; height:100% ; float:right; "  codebase="download/IScanClientOCX.exe" classid="clsid:455FA7A9-756E-4767-8A0A-40DDECD23659">
			<a class="toolBtn" href="${ocxPath}OcxHD.exe" id="downloadVideoControl">下载视频控件</a>
			
			</object>
		</div>
		<div class="chart">
		<div style="width:100%;height:30%;padding-top:10px;">
		
		<table class="table">
			<tr>
				<td>图片</td>
				<td>疲劳报警</td>
				<td>夜间行车</td>
				<td>超速报警</td>
				<td>道路类型超速报警</td>
			</tr>
			<tr>
				<td><a class="db" href="javascript:;" id="imageSpan" onclick="clickimageSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="tiredSpan" onclick="clicktiredSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="nightSpan" onclick="clicknightSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="speedSpan" onclick="clickspeedSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="roadLevelSpeedSpan" onclick="clickroadLevelSpeedSpan()">-</a></td>
			</tr>
		</table>
	</div>
		<div id="speedCharts" style="width:100%;height:70%"></div>
	</div>
	</div>
	<div class="map-track">
		<div id="gdMap"></div>
		<div id="speedDiv">
			<div id="trackList"></div>
		</div>
	</div>
</div>

<!-- 用于控制弹出窗口- -->
<a class="dn" id="txtOpenWindow" target="_self"></a>
<div id="tooldiv">
		<a class="toolBtn" href="javascript:;" style="display:none" id="btnStopVideoDownload" onclick="stopDownloadVedioFile()">停止视频下载</a>
		<a class="toolBtn" href="javascript:;" style="display:none" id="btnStopVideoReplay" onclick="StopBack()">停止视频回放</a>
		<!-- <select style="width:130px;margin: 0px;" id="timeOutSel">
		<option value ="300" selected="selected">5分钟后关闭</option>
  		<option value ="600">10分钟后关闭</option>
  		<option value="1200">20分钟后关闭</option>
  		<option value="1800">30分钟后关闭</option>
  		</select>
  		<span id="t_m">00分</span> 
		<span id="t_s">00秒</span> -->
		<button class="btn dn" id="closeVideoDiv" >关闭视频</button>
		<button class="btn dn" id="downLoadVideoDiv" onclick="downLoadVideo()">下载视频</button>
		<a class="toolBtn" id="setVideoDiv" href="javascript:;" onclick="setVideo()" >查询</a>
		<select id="selectVehicleSel" onchange="changeVechile()"  style="width:100px;margin: 0px;">
		</select>
	</div>
	
<!-- Modal -->
<div id="myModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width:300px;left: 90%;top:5%;">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h5 id="myModalLabel">视频回放查询</h5>
  </div>
  <div class="modal-body">
    <ul class="videoTable" stle="">
				<li>设备ID：</li>
				<li class="bt10"><input type="text" id="devid" value="" disabled="disabled"></li>
				<li>通道号：</li>
				<li class="bt10">
					<select id="ChannelNo" value=''>
						<option value="0" selected="selected">1</option>
						<option value="1">2</option>
						<option value="2">3</option>
						<option value="3">4</option>
					</select>
				</li>
				<li>回放下载时间段：</li>
				<li class="bt10">
					<select onchange="changeBackSelect()" id="videoBack" value="">
					</select>
				</li>
				<li>开始时间：</li>
				<li class="bt10"><input type="text" class="Wdate" name="startDate" id="startDate" onclick="WdatePicker({isShowClear:false,dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endDate\')}'})" />   </li>
				
				<!-- <li class="bt10"><input type="text" class="Wdate" name="startDate" id="startDate" onclick="WdatePicker({isShowClear:false,dateFmt:'yyyy-MM-dd  HH:mm:ss',maxDate:'#F{$dp.$D(\'endDate\')}'})" />  </li> -->
				<li>结束时间：</li>
				<li class="bt10"><input type="text" class="Wdate" name="endDate" id="endDate" onclick="WdatePicker({isShowClear:false,dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startDate\')}',maxDate:'%y-%M-%d %H:%m:%s'})" />   </li>

				<li>进度条<span style="color:red;">：下载路径 D:\video\ </span>：
				</li>
			</ul>
			<div class="progress progress-striped active" style="width: 240px; margin-bottom: 10px;">
  <div id="downbar" class="bar" style="width: 0%;"></div>
</div>
  </div>
  <div class="modal-footer">
 	 <a class="toolBtn" href="javascript:;" onclick="QueryDevRecordFiles()">查询</a>
 	 &nbsp;&nbsp;
 	 <a class="toolBtn" href="javascript:;" id="btnPlayBack"  >回放</a>
 	 &nbsp;&nbsp;
 	 <a class="toolBtn" href="javascript:;" id="btnVideoDown" >下载</a>
 	 &nbsp;&nbsp;
 	 <a class="toolBtn" href="javascript:;" id="btnVideoDown" data-dismiss="modal" aria-hidden="true" style="background-color: #0066cc;" >关闭</a>
<!--     <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button> -->
  </div>
</div>




<script>


    
	

var oneDay = 10 * 1000;
var date = [];

var data = [];
var now = new Date();
var nowstr="";
var vehicleID ="${vehicleID}";

var commno ="${commno}";
var regNO ="${registrationNO}";
var internal_number ="${internal_number}";

var vehicleNO ="${vehicleNO}";
var videoOverTime = ${ownerSetting.videoOverTime!=null?ownerSetting.videoOverTime:60}; 
var fileVersion = "1.0.1.0";//当前版本号

var RegistrationNO ='${RegistrationNO}';
var user='${user}';
var password='${password}';
var ip='${ip}';   
var port='${port}';
var deviceId='${deviceId}';

var intsetInterval=0;
var isinitselect = true;
var  appCtx="${appCtx}";
var defaultTime =60;

var queryStartTime="";
var queryEndTime="";
var playStartTime="";
var playEndTime="";

var dataArray=new Array(); 
var videoCache = new HashMap();

var imageAlarmArray=[];
var marketArray=[];
var lineListArray=[];

var videoImagesList=[];
var videoTiredAlarmList=[];
var videoNightAlarmList=[];
var videoSpeedAlarmList=[];
var videoRoadLevelSpeedAlarmList=[];

var isShowImages=false;
var isShowTireAlarm=false;
var isShowNightAlarm=false;
var isShowSpeedAlarm=false;
var isShowRoadAlarm=false;


var imagesList=[];
var tireAlarmList=[];
var nightAlarmList=[];
var speedAlarmList=[];
var roadAlarmList=[];

var map;
var myChart;

var alarmImages="http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png";
var option = {
	    xAxis: {
	        type: 'category',
	        boundaryGap: false,
	        data: date
	    },
	    grid:{
	    	x:30,
	    	y:30,
	    	x2:10,
	    	y2:10
	    	
	    },
	    tooltip: {
	        trigger: 'axis',
	        formatter: function (params) {
	            params = params[0];
	            return "时间:"+params.name+"<br/>"+"速度"+params.value;
	        },
	        axisPointer: {
	            animation: false
	        }
	    },
	    yAxis: {
	        boundaryGap: [0, '50%'],
	        name : '速度(km/h)',
		    type : 'value',
		    max : 150,
	    },
	    series: [
	        {
	            name:'速度',
	            type:'line',
	            smooth:true,
	            symbol: 'none',
	            stack: 'a',
	            data: data
	        }
	    ]
	};
	
$(function(){ 
	try{

		map = new AMap.Map('gdMap', {
	        resizeEnable: true,
	        zoom:11,
	        center: [116.397428, 39.90923]
	    });
		myChart = echarts.init(document.getElementById('speedCharts'));
		myChart.setOption(option);
		updatemyChart();
			
		 initVehicleList();
		 initTable();
	//	 queryVehicleTrack();
		 $("#devid").val(deviceId);
		 $("#startDate").val(getDay(1));
		 $("#endDate").val(getDay(0));
		 $("#btnPlayBack").unbind("click");
		 $("#btnPlayBack").bind("click",PlayBack);
		 $("#btnPlayBack").html("回放");
		 
		 $("#btnVideoDown").unbind("click");
		 $("#btnVideoDown").bind("click",DownloadByTime);
		 $("#btnVideoDown").html("下载");
		 
		 
	     login(); 
		 /* 
		initVehicleList();
		 defaultTime =$("#timeOutSel").val();
		 setTimeout("afterrender()", 3000 ); 
		 
		 $("#closeVideoDiv").unbind("click");
		 $("#closeVideoDiv").bind("click",buttonCloseVideo);
		 $("#closeVideoDiv").html("关闭视频") */
	}catch(e){
		  
	}
});    


function updatemyChart() {
    myChart.setOption({
        xAxis: {
            data: date
        },
        series: [{
            name:'速度',
            data: data
        }]
    });
}

function initTable(){
	$("#trackList").flexigrid({
        dataType : 'json',
        colModel : [{
        	display : '序号',
            name : 'id',
            width : 50,
            sortable : true,
            align : 'left'
        },{
            display : '车牌号',
            name : 'registrationNO',
            width : 120,
            sortable : false,
            align : 'left'
        },{
            display : '自编号',
            name : 'internal_number',
            width : 120,
            sortable : false,
            align : 'left'
        },{
            display : '定位时间',
            name : 'gps_time',
            width : 150,
            sortable : false,
            align : 'left',    
        },{
            display : '里程(km)',
            name : 'gps_mileage',
            width : 100,
            sortable : false,
            align : 'left',    
        },{
            display : '速度(km/h)',
            name : 'gps_speed',
            width : 100,
            sortable : false,
            align : 'left',    
        },{
            display : '纬度',
            name : 'latitude',
            width : 120,
            sortable : false,
            align : 'left',    
        },{
            display : '经度',
            name : 'longitude',
            width : 120,
            sortable : false,
            align : 'left',    
        },{
            display : '位置信息',
            name : 'address',
            width : 235,
            sortable : false,
            align : 'left',
            paramcolnames : ['id','longitude','latitude','gps_time','gps_mileage','gps_speed'],
			handlefunction: getAddress
        }],
        resizable : false,
        sortname : "id",// 第一次加载数据时排序列
        sortorder : "asc",// 第一次加载数据时排序类型
        usepager : false,// 是否分页，默认为true。
        showToggleBtn : false,
        showTableToggleBtn : false,// 是否显示收起/打开按钮,默认不显示。
        rowId : 'id',// 多选框绑定行的id,只有checkbox : true时才有效。
        width : '80%',// 表格宽度
        titDisplay:false,
        onSuccess : function(data){
        	if(isToday(playEndTime.substring(0,4)+"-"+playEndTime.substring(4,6)+"-"+playEndTime.substring(6,8)+" "+playEndTime.substring(8,10)+":"+playEndTime.substring(10,12)+":"+playEndTime.substring(12,14))){
        		videoTiredAlarmList=[];
        		videoNightAlarmList=[];
        		videoSpeedAlarmList=[];
        		videoRoadLevelSpeedAlarmList=[];
        		$("#tiredSpan").html("-");
        		$("#nightSpan").html("-");
        		$("#speedSpan").html("-");
        		$("#roadLevelSpeedSpan").html("-");
        		if(data&&data.rows&&data.rows.length>0){
        			videoImagesList=data.rows[0].hisPicList;
        			$("#imageSpan").html(videoImagesList.length);
        		}
        	}else{
        		if(data&&data.rows&&data.rows.length>0){
        			videoImagesList=data.rows[0].hisPicList;
            		videoTiredAlarmList=data.rows[0].tiredAlarmList;
            		videoNightAlarmList=data.rows[0].nightAlarmList;
            		videoSpeedAlarmList=data.rows[0].speedAlarmList;
            		videoRoadLevelSpeedAlarmList=data.rows[0].roadLevelSpeedAlarmList;
            		$("#tiredSpan").html(videoTiredAlarmList.length);
            		$("#nightSpan").html(videoNightAlarmList.length);
            		$("#speedSpan").html(videoSpeedAlarmList.length);
            		$("#roadLevelSpeedSpan").html(videoRoadLevelSpeedAlarmList.length);
            		$("#imageSpan").html(videoImagesList.length);
            	}
        	}
        	
        	if(lineListArray.length>1){
        		map.setCenter(new AMap.LngLat(lineListArray[0][0],lineListArray[0][1]));
  			 	var polyline = new AMap.Polyline({
  			        path: lineListArray,          //设置线覆盖物路径
  			        strokeColor: "#3366FF", //线颜色
  			        strokeOpacity: 1,       //线透明度
  			        strokeWeight: 5,        //线宽
  			        strokeStyle: "solid",   //线样式
  			        strokeDasharray: [10, 5] //补充线样式
  			    });
  			    polyline.setMap(map);
  		 	}
        	updatemyChart();
        },
        onSelectRow : function(row){
        	map.remove(marketArray);
        	marketArray=[];
        	map.setCenter(new AMap.LngLat(row.longitude, row.latitude));
        	
        	var marker = new AMap.Marker({
    	        map:map,
    	        position: [row.longitude, row.latitude],
    	        offset: new AMap.Pixel(-15, -10),
    	        icon:appCtx + "resources/images/mapTool/car1.png"
    	    });
    		var infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)}); 
    		marker.content = '定位时间：'+row.gps_time+'</br>速度：'+row.gps_speed+' 公里/小时</br>里程：'+row.gps_mileage+' 公里';
    		marker.on('click', function(e){
    			 isopenWin=true;
    			 infoWindow.setContent(e.target.content);
    		     infoWindow.open(map, e.target.getPosition());
    		     
    		   	 
    		});
    		marketArray.push(marker);
    		marketArray.push(infoWindow);
        },
        onSelectAllRow : function(data){

        }
    });
}

function closeInfoWindow() {
    map.clearInfoWindow();
}

function clickimageSpan(){
	isShowImages=!isShowImages;
	if(isShowImages){ 
		if(videoImagesList.length>0){
			map.setCenter(new AMap.LngLat(videoImagesList[0].gdLng,videoImagesList[0].gdLat));
		for(var i=0;i<videoImagesList.length;i++){
			var marker = new AMap.Marker({
		        map: map,
		        position: [videoImagesList[i].gdLng,videoImagesList[i].gdLat]
		    });
			var infoWindow = new AMap.InfoWindow({isCustom: true,offset: new AMap.Pixel(0, -10)}); 
			marker.content = "<div style='padding:15px;border:1px solid #dedede;background:#fff;position:relative;'><a  onclick='closeInfoWindow()' style='position:absolute;top:3px;right:3px;background:url(http://webapi.amap.com/images/close2.gif) 0 0 no-repeat;width:10px;height:10px;' href='javascript:;'></a><img class='db' style='height:200px;weight:300px;' src='"+videoImagesList[i].imgUrl+"'><p style='padding-top:15px;'>拍照时间："+videoImagesList[i].gpsTimeStr+"</p></div>";
			marker.on('click', function(e){
				 isopenWin=true;
				 infoWindow.setContent(e.target.content);
			     infoWindow.open(map, e.target.getPosition());
			     
			   	 
			});
			imagesList.push(marker);
			imagesList.push(infoWindow);
		}
		}
		
	}else{
		map.remove(imagesList);
		imagesList=[];
	}
}

function clicktiredSpan(){
	isShowTireAlarm=!isShowTireAlarm;
	if(isShowTireAlarm){
		if(videoTiredAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoTiredAlarmList[0].sLon,videoTiredAlarmList[0].sLat));
			for(var i=0;i<videoTiredAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoTiredAlarmList[i].sLon,videoTiredAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "疲劳报警"+(i+1)+"</br> 开始时间："+videoTiredAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoTiredAlarmList[i].eLon,videoTiredAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "疲劳报警"+(i+1)+"</br> 结束时间："+videoTiredAlarmList[i].endTime
				});
				tireAlarmList.push(marker);
				tireAlarmList.push(marker1);
			}
		}
		
	}else{
		map.remove(tireAlarmList);	
		tireAlarmList=[];
	}
}

function clicknightSpan	(){
	isShowNightAlarm=!isShowNightAlarm;
	if(isShowNightAlarm){
		if(videoNightAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoNightAlarmList[0].sLon,videoNightAlarmList[0].sLat));
			for(var i=0;i<videoNightAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoNightAlarmList[i].sLon,videoNightAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "夜间行车"+(i+1)+"</br> 开始时间："+videoNightAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoNightAlarmList[i].eLon,videoNightAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "夜间行车"+(i+1)+"</br> 结束时间："+videoNightAlarmList[i].endTime
				});
				
				nightAlarmList.push(marker);
				nightAlarmList.push(marker1);
			}
		}
	}else{
		map.remove(nightAlarmList);
		nightAlarmList=[];
	}
}

function clickspeedSpan(){
	isShowSpeedAlarm=!isShowSpeedAlarm;
	if(isShowSpeedAlarm){
		if(videoSpeedAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoSpeedAlarmList[0].sLon,videoSpeedAlarmList[0].sLat));
			for(var i=0;i<videoSpeedAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoSpeedAlarmList[i].sLon,videoSpeedAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "超速报警"+(i+1)+"</br> 开始时间："+videoSpeedAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoSpeedAlarmList[i].eLon,videoSpeedAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "超速报警"+(i+1)+"</br> 结束时间："+videoSpeedAlarmList[i].endTime
				});
				
				speedAlarmList.push(marker);
				speedAlarmList.push(marker1);
			}
		}
	}else{
		map.remove(speedAlarmList);
		speedAlarmList=[];
	}
}

function clickroadLevelSpeedSpan(){
	isShowRoadAlarm=!isShowRoadAlarm
	if(isShowRoadAlarm){
		if(videoRoadLevelSpeedAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoRoadLevelSpeedAlarmList[0].sLon,videoRoadLevelSpeedAlarmList[0].sLat));
			for(var i=0;i<videoRoadLevelSpeedAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoRoadLevelSpeedAlarmList[i].sLon,videoRoadLevelSpeedAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "道路类型超速报警"+(i+1)+"</br> 开始时间："+videoRoadLevelSpeedAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoRoadLevelSpeedAlarmList[i].eLon,videoRoadLevelSpeedAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "道路类型超速报警"+(i+1)+"</br> 结束时间："+videoRoadLevelSpeedAlarmList[i].endTime
				});
				
				roadAlarmList.push(marker);
				roadAlarmList.push(marker1);
			}
		}
	}else{
		map.remove(roadAlarmList);
		roadAlarmList=[];
	}
}


function isToday(str){
	var d=new Date(Date.parse(str.replace(/\-/g, "\/")));
	if (d.toDateString() == new Date().toDateString()){
		return true;
	}else{
		return false;
	}
}


function showAddress(id,lon,lat){
	var ctrl="#address_"+id;
	var geocoder = new AMap.Geocoder({
        radius: 1000,
        extensions: "all"
    });        
    geocoder.getAddress(new AMap.LngLat(lon,lat), function(status, result) {
        if (status === 'complete' && result.info === 'OK') {
        	var address=result.regeocode.formattedAddress;
        	$(ctrl).text(address);
        }
    });  
}


function getAddress(id,lon,lat,gps_time,gps_mileage,gps_speed){
	date.push(gps_time);
	data.push(gps_speed);
	
	 var arrgps=[];
		 arrgps.push(lon);
		 arrgps.push(lat);
	lineListArray.push(arrgps);
	showAddress(id,lon,lat);
	return '<span id="address_' + id + '">'+'</span>';
};

function initVehicleList(){
	$.ajax({
		type : 'post',
		async : false,
		url : appCtx + "/video/queryVideoVehicleList.html",
		cache : false,
		dataType : "JSON",
		success : function(data) {
			if(data){

				$('#selectVehicleSel').select2({
				  data: data
				})
				
				$('#selectVehicleSel').val(vehicleID).trigger("change");
			}
		}
	});

}

function timeOut(){
	if(defaultTime>0){
		defaultTime--;
		var m=Math.floor(defaultTime/60%60); 
		var s=Math.floor(defaultTime%60);
		if(m<10){
			document.getElementById("t_m").innerHTML = "0"+m + "分"; 
		}else{
			document.getElementById("t_m").innerHTML = m + "分"; 
		}
		if(s<10){
			document.getElementById("t_s").innerHTML = "0"+s + "秒";
		}else{
			document.getElementById("t_s").innerHTML = s + "秒";
		}
	}else{
		document.getElementById("t_m").innerHTML = "00" + "分";
		document.getElementById("t_s").innerHTML = "00" + "秒";
		window.clearInterval(intsetInterval);
		stopRealPlay();  
		$("#closeVideoDiv").unbind("click");
		$("#closeVideoDiv").bind("click",buttonOpenVideo);
		$("#closeVideoDiv").html("打开视频")
	}
}

function buttonOpenVideo(){
	 defaultTime =$("#timeOutSel").val();
	 realPlay();
	 intsetInterval=window.setInterval("timeOut();", 1000);
	 $("#closeVideoDiv").unbind("click");
	 $("#closeVideoDiv").bind("click",buttonCloseVideo);
	 $("#closeVideoDiv").html("关闭视频")
}
function buttonCloseVideo(){
	defaultTime=0;
	document.getElementById("t_m").innerHTML = "00" + "分";
	document.getElementById("t_s").innerHTML = "00" + "秒";
	window.clearInterval(intsetInterval);
	stopRealPlay();
	$("#closeVideoDiv").unbind("click");
	$("#closeVideoDiv").bind("click",buttonOpenVideo);
	$("#closeVideoDiv").html("打开视频")
}/* 
function setTimeOut(){
	realPlay();
	 $("#resetTimeout").hide();
	 $("#time_label").show();
	defaultTime = videoOverTime;
} */

IScanClientOCXCtrlParam = function(){ 
    return {
        resultInitial:null,
        resultLogin:null,
        videoCtrl : new Array(17),//针对通道，包括通道信息(data:object)、是否打开声音(sound:bool)，从1开始
        curPresetControl : -1, //39表示调用，8表示设置，9表示删除
        talkCtrl : null,//已打开对讲的设备信息,
		talkDevAddr: null, // 已打开对讲设备地址
		talkDevName: null, // 已打开对讲设备名
        deviceAddress:null,//设备地址
        devName:null,
        state:null,//判断是否已经登录
        picturePath : 'D:\\picture\\',
        vedioPath : 'D:\\video\\',
        groupsCtrl: new Array(64),
        sound_first:0,//获取窗口消息，实时存取窗口号
        //sound_second:0,
        sound_third:0,//打开声音后的窗口号
        sound_fouth:0,//打开第二个窗口后，存放第一个窗口号
        errorInfo :['没有对讲权限','登录dns服务器失败','连接流媒体服务器失败','网络响应超时','网络错误','由于网络原因或DVR忙，注册失败（连接服务器失败）',
            '超过了用户所在机构下的最大输出流','超过了流媒体的最大输出数限制','超过了服务器最大的输出流','没有视频监控权限','未知错误',
            '连续登录失败次数超过限定，用户将被锁定一段时间','多次登录失败，需退出程序','用户密钥错误','用户已过期','版本不匹配',
            '用户被禁用','用户已经登录','服务器地址无效','用户没有权限','用户名或密码错误','连接服务器失败','无效参数','内存错误',
            '没有登录','参数没有初始化','登录失败','登录成功'],
        destroy : function(){
            this.videoCtrl = new Array(17);
            this.talkCtrl = null;
            this.deviceAddress = null;
            this.state = null;
            this.picturePath = 'D:\\picture\\';
            this.vedioPath = 'D:\\video\\';
			this.talkDevAddr = null;
			this.talkDevName = null;
        }
    }
}();


function afterrender(){
   
	login();
	
	setTimeout(function(){
		realPlay();
	},5000)
    
}
/* //键盘控制回车登录事件；
document.onkeydown = function(e){
    e = window.event || e;
    var ke = e.keyCode || e.which;
    if(13 == ke){
        login();
    }
}   */
//登录
function login(){ 
    if(IScanClientOCXCtrlParam.state){
        alert("请退出系统再重新登录");
        return;
    }
     //user = "yccs";
     //password = "123456";
     //ip = "211.162.75.141";
     //port = "52460";
   
    if(!user||!password||!ip||!port){
        alert('用户名、密码、ip或端口号为空');
        return;
    }

    var resultInitial = IScanClientOCXCtrl.CX_Initial(ip, port, '0', '0');
    IScanClientOCXCtrl.CX_SetVideoMode(1);
    if(0 != resultInitial){
        alert('插件初始化失败,请检查是否安装!')
        return;
    }
    var resultLogin = IScanClientOCXCtrl.CX_Login(user, password);
    for(var i = 0;i < IScanClientOCXCtrlParam.errorInfo.length;i++){
        if((resultLogin + 27) == 27){ 
           
            IScanClientOCXCtrlParam.state = true;
          
            break;
        }else if(i == (resultLogin + 27)){
            var errorInfo = IScanClientOCXCtrlParam.errorInfo[i]
            alert(errorInfo);//输出错误信息
            return;
        }
    }
    IScanClientOCXCtrlParam.resultInitial = resultInitial;
    IScanClientOCXCtrlParam.resultLogin = resultLogin;
    var deviceList = IScanClientOCXCtrl.CX_GetDeviceList();
   
}


//实时预览
function realPlay(){ 
    if(0 == IScanClientOCXCtrlParam.resultInitial && 0== IScanClientOCXCtrlParam.resultLogin){
 
        var result = IScanClientOCXCtrl.CX_RealPlay(0, deviceId, 1, 0);
        if(0 == result){
            IScanClientOCXCtrlParam.videoCtrl[0] = new Object();
            IScanClientOCXCtrlParam.videoCtrl[0].devAddress = deviceId;
            IScanClientOCXCtrlParam.videoCtrl[0].channelNum = 1;
            IScanClientOCXCtrlParam.videoCtrl[0].devName = RegistrationNO;
            IScanClientOCXCtrlParam.videoCtrl[0].sound = false;
            IScanClientOCXCtrl.CX_PTZControl(0,8,63,0);
        }
		var result2 = IScanClientOCXCtrl.CX_RealPlay(1, deviceId, 2, 1);
        if(0 == result2){
            IScanClientOCXCtrlParam.videoCtrl[1] = new Object();
            IScanClientOCXCtrlParam.videoCtrl[1].devAddress = deviceId;
            IScanClientOCXCtrlParam.videoCtrl[1].channelNum = 2;
            IScanClientOCXCtrlParam.videoCtrl[1].devName = RegistrationNO;
            IScanClientOCXCtrlParam.videoCtrl[1].sound = false;
            IScanClientOCXCtrl.CX_PTZControl(1,8,63,0);
        }
		var result3 = IScanClientOCXCtrl.CX_RealPlay(2, deviceId, 3, 2);
        if(0 == result3){
            IScanClientOCXCtrlParam.videoCtrl[2] = new Object();
            IScanClientOCXCtrlParam.videoCtrl[2].devAddress = deviceId;
            IScanClientOCXCtrlParam.videoCtrl[2].channelNum = 3;
            IScanClientOCXCtrlParam.videoCtrl[2].devName = RegistrationNO;
            IScanClientOCXCtrlParam.videoCtrl[2].sound = false;
            IScanClientOCXCtrl.CX_PTZControl(2,8,63,0);
        }
		var result4 = IScanClientOCXCtrl.CX_RealPlay(3, deviceId, 4, 3);
        if(0 == result4){
            IScanClientOCXCtrlParam.videoCtrl[3] = new Object();
            IScanClientOCXCtrlParam.videoCtrl[3].devAddress = deviceId;
            IScanClientOCXCtrlParam.videoCtrl[3].channelNum = 4
            IScanClientOCXCtrlParam.videoCtrl[3].devName = RegistrationNO;
            IScanClientOCXCtrlParam.videoCtrl[3].sound = false;
            IScanClientOCXCtrl.CX_PTZControl(3,8,63,0);
        }
        soundOpen();
    }
}
//
function  stopRealPlay(){
    if(0 == IScanClientOCXCtrlParam.resultInitial && 0== IScanClientOCXCtrlParam.resultLogin){
    	var port0 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(0);
        var result0 = IScanClientOCXCtrl.CX_StopRealPlay(0);
        var port1 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(1);
        var result1 = IScanClientOCXCtrl.CX_StopRealPlay(1);
        var port2 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(2);
        var result2 = IScanClientOCXCtrl.CX_StopRealPlay(2);
    	var port3 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(3);
        var result3 = IScanClientOCXCtrl.CX_StopRealPlay(3);
        if(0 == result1){
        	IScanClientOCXCtrlParam.videoCtrl[0] = null;
        	IScanClientOCXCtrlParam.videoCtrl[1] = null;
        	IScanClientOCXCtrlParam.videoCtrl[2] = null;
        	IScanClientOCXCtrlParam.videoCtrl[3] = null;
        }else{
            alert('停止预览失败，请确认该窗口视频是否打开！')
        }
        //soundClose();
        
    }
}

//打开声音
function soundOpen(){
    if(0 == IScanClientOCXCtrlParam.resultInitial && 0== IScanClientOCXCtrlParam.resultLogin){    
        var port1 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(1);   
        if(IScanClientOCXCtrlParam.videoCtrl[1].sound){
            //                        var res = IScanClientOCXCtrl.CX_StopSound(curSelWinNum);
            //                        IScanClientOCXCtrlParam.videoCtrl[curSelWinNum].sound = false;
            return;
        }else{
            var result1 = IScanClientOCXCtrl.CX_PlaySound(port1);
            if(0 == result1){
                IScanClientOCXCtrlParam.videoCtrl[1].sound = true
            }      
        }
        
        var port2 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(2);   
        if(IScanClientOCXCtrlParam.videoCtrl[1].sound){
            //                        var res = IScanClientOCXCtrl.CX_StopSound(curSelWinNum);
            //                        IScanClientOCXCtrlParam.videoCtrl[curSelWinNum].sound = false;
            return;
        }else{
            var result2 = IScanClientOCXCtrl.CX_PlaySound(port2);
            if(0 == result2){
                IScanClientOCXCtrlParam.videoCtrl[1].sound = true
            }      
        }
        
        var port3 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(3);   
        if(IScanClientOCXCtrlParam.videoCtrl[1].sound){
            //                        var res = IScanClientOCXCtrl.CX_StopSound(curSelWinNum);
            //                        IScanClientOCXCtrlParam.videoCtrl[curSelWinNum].sound = false;
            return;
        }else{
            var result3 = IScanClientOCXCtrl.CX_PlaySound(port3);
            if(0 == result3){
                IScanClientOCXCtrlParam.videoCtrl[1].sound = true
            }      
        }


    }
}
//关闭声音
function soundClose(){
    if(0 == IScanClientOCXCtrlParam.resultInitial && 0== IScanClientOCXCtrlParam.resultLogin){
       
        var port1 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(1);
        if(IScanClientOCXCtrlParam.videoCtrl[1].sound){
            var res1 = IScanClientOCXCtrl.CX_StopSound(port1);
            if(0 == res1){
                IScanClientOCXCtrlParam.sound_first = 0;
                IScanClientOCXCtrlParam.sound_third = 0;
                IScanClientOCXCtrlParam.sound_fouth = 0;
                IScanClientOCXCtrlParam.videoCtrl[1].sound = false;
            }

        }
        var port2 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(2);
        if(IScanClientOCXCtrlParam.videoCtrl[1].sound){
            var res2 = IScanClientOCXCtrl.CX_StopSound(port2);
            if(0 == res2){
                IScanClientOCXCtrlParam.sound_first = 0;
                IScanClientOCXCtrlParam.sound_third = 0;
                IScanClientOCXCtrlParam.sound_fouth = 0;
                IScanClientOCXCtrlParam.videoCtrl[1].sound = false;
            }

        }
        var port3 = IScanClientOCXCtrl.CX_GetPlayPortByWndNum(3);
        if(IScanClientOCXCtrlParam.videoCtrl[1].sound){
            var res3 = IScanClientOCXCtrl.CX_StopSound(port3);
            if(0 == res3){
                IScanClientOCXCtrlParam.sound_first = 0;
                IScanClientOCXCtrlParam.sound_third = 0;
                IScanClientOCXCtrlParam.sound_fouth = 0;
                IScanClientOCXCtrlParam.videoCtrl[1].sound = false;
            }

        }
    }
}



function QueryDevRecordFiles(){
	
	map.remove(marketArray);
	map.remove(imageAlarmArray);
	map.remove(imagesList);
	map.remove(tireAlarmList);
	map.remove(nightAlarmList);
	map.remove(speedAlarmList);
	map.remove(roadAlarmList);
	imagesList=[];
	tireAlarmList=[];
	nightAlarmList=[];
	speedAlarmList=[];
	roadAlarmList=[];
	imageAlarmArray=[];
	marketArray=[];
	lineListArray=[];
	videoImagesList=[];
	videoTiredAlarmList=[];
	videoNightAlarmList=[];
	videoSpeedAlarmList=[];
	videoRoadLevelSpeedAlarmList=[];
	date = [];
	data = [];
	
	queryStartTime=$.trim($('#startDate').val());
	queryEndTime=$.trim($('#endDate').val());
	
	dataArray=[];
	videoCache.clear();
	var obj=document.getElementById('videoBack'); 
	obj.options.length=0;
	

	queryStartTime=queryStartTime.substr(0,4)+queryStartTime.substr(5,2)+queryStartTime.substr(8,2)+queryStartTime.substr(11,2)+queryStartTime.substr(14,2)+queryStartTime.substr(17,2);
	queryEndTime=queryEndTime.substr(0,4)+queryEndTime.substr(5,2)+queryEndTime.substr(8,2)+queryEndTime.substr(11,2)+queryEndTime.substr(14,2)+queryEndTime.substr(17,2);
	
    var channelNum = document.getElementById("ChannelNo").value;     
    var videoType = 'history';        
	 // alert(startTime + "," + endTime + "," + devId + "," + videoType + ","  + channelNum);
   	var vedioList = IScanClientOCXCtrl.CX_QueryVideoFlie(queryStartTime, queryEndTime, deviceId, videoType, channelNum);
   	var xmlDoc=loadXML(vedioList);
   	var elements = xmlDoc.getElementsByTagName("NodeInfo");
	if(elements.length==0){
		alert("没有找到查询日期内的视频资料！");
		return;
	}
	for (var i = 0; i < elements.length; i++) {
		var fileData= new Object();
        var fileName = elements[i].getElementsByTagName("NodeFilename")[0].firstChild.nodeValue;
        fileData.FileName=fileName;
        var fileSize = elements[i].getElementsByTagName("NodeFileSize")[0].firstChild.nodeValue; 
        fileData.FileSize=fileSize;
        var startTime = elements[i].getElementsByTagName("NodeStartTime")[0].firstChild.nodeValue; 
        fileData.startTime=startTime;
        var stopTime = elements[i].getElementsByTagName("NodeEndTime")[0].firstChild.nodeValue; 
        fileData.stopTime=stopTime;
        fileData.Channel=channelNum;
        var videoBackSelect=document.getElementById("videoBack");
      
        var a=new Option();
        a.value=fileName;
        a.text=startTime.substr(0,4)+"-"+startTime.substr(4,2)+"-"+startTime.substr(6,2)+" "+startTime.substr(8,2)+":"+startTime.substr(10,2)+":"+startTime.substr(12,2)+"~"+stopTime.substr(8,2)+":"+stopTime.substr(10,2)+":"+stopTime.substr(12,2);
        videoBackSelect.options.add(a);
        dataArray.push(fileData);
        videoCache.put(fileName,fileData);
	}
	playStartTime=dataArray[0].startTime;
	playEndTime=dataArray[0].stopTime;
	var fileflag=elements[0].getElementsByTagName("NodeFilename")[0].firstChild.nodeValue;
	$("#filename").val(fileflag);
	
} 

function PlayBack(){
	queryVehicleTrack();
	map.remove(marketArray);
	map.remove(imageAlarmArray);
	map.remove(imagesList);
	map.remove(tireAlarmList);
	map.remove(nightAlarmList);
	map.remove(speedAlarmList);
	map.remove(roadAlarmList);
	imagesList=[];
	tireAlarmList=[];
	nightAlarmList=[];
	speedAlarmList=[];
	roadAlarmList=[];
	imageAlarmArray=[];
	marketArray=[];
	lineListArray=[];
	videoImagesList=[];
	videoTiredAlarmList=[];
	videoNightAlarmList=[];
	videoSpeedAlarmList=[];
	videoRoadLevelSpeedAlarmList=[];
	date = [];
	data = [];

	 
	var channelNum = document.getElementById("ChannelNo").value;
	if(!playStartTime||!playStartTime||playStartTime==""||playEndTime==""){
		alert("请先查询录像，并选择所需回放的录像段！");  
		return;
	}
	var playCode = IScanClientOCXCtrl.CX_PlayVideoFile(deviceId, playStartTime, playEndTime, channelNum, 0);  
	$("#btnPlayBack").unbind("click");
	 $("#btnPlayBack").bind("click",StopBack);
	 $("#btnPlayBack").html("停止");
	 $("#btnStopVideoReplay").css("display","inline-block");
	 queryVehicleTrack();
	if(playCode == 0){
		console.log("开始播放录像！");
	}else{
		console.log("播放录像失败！");
	}
}

function StopBack(){
	
	
	 
	 
	var playCode = IScanClientOCXCtrl.CX_StopVideoPlay(0);      
	if(playCode == 0){
		console.log( "停止回放成功！");
	}else{
		console.log("停止回放失败！");
	}
	$("#btnPlayBack").unbind("click");
	 $("#btnPlayBack").bind("click",PlayBack);
	 $("#btnPlayBack").html("回放");
	 $("#btnStopVideoReplay").css("display","none");
}

function DownloadByTime(){
	
	
	
	var channelNum = document.getElementById("ChannelNo").value;

	if(!playStartTime||!playStartTime||playStartTime==""||playEndTime==""){
		alert("请先查询录像，并选择所需下载的录像段！");  
		return;
	}
	
	 var num = [];
     var fso = new ActiveXObject('Scripting.FileSystemObject'); 
     for(var i = 0; ; i++){
         var strDrive = String.fromCharCode(99 + i);
         if(fso.DriveExists(strDrive)){
             num[num.length] = fso.GetDrive(strDrive).DriveLetter;                            
         }
         if(num.length === fso.Drives.Count){
             break;
         }
     }    
     var pflag = true;
     if(IScanClientOCXCtrlParam.vedioPath.toString().length >= 1){
         var pcitureOne = IScanClientOCXCtrlParam.vedioPath.toString().substring(0,1);
         for(var i = 0; i < num.length;i++ ){
             if( (pcitureOne.toUpperCase()) != num[i] ){
                 continue;
             }else{
                 pflag = false;
             }
         }
     }
     if(pflag){
         alert('存放下载录像的磁盘不存在,请重新选择磁盘')
         return;
     }
     // var fso = new ActiveXObject('Scripting.FileSystemObject');
     if(false == fso.FolderExists(IScanClientOCXCtrlParam.vedioPath)){  
         var str_picturePath = IScanClientOCXCtrlParam.vedioPath;
         var str_msg ="路径不存在，是否创建路径？"
         // var str_msg = "<br>"+IScanLang.PICTUREPATH_NO_EXISTENT_MSG;
         var answer = confirm(str_picturePath + str_msg);
         if(answer){
             try{
                 var fso = new ActiveXObject('Scripting.FileSystemObject');
                 if(false == fso.FolderExists(IScanClientOCXCtrlParam.vedioPath)){
                     fso.CreateFolder(IScanClientOCXCtrlParam.vedioPath);
                 }
             }catch(e){
                 alert('默认创建只支持一级目录的创建，请重新创建');
                 return;
             }
         }else{
             return;
         }

         fso = null;


     }else{
         fso = null;

     }
     
	
	var pictureName = deviceId + '_' + channelNum + '_' + playStartTime + '.mp4'; 
	
	var filePath="D:\\video\\"+pictureName;
	
/* 	var pictureName = deviceId + '_' + channelNum + '_' + playStartTime + '.mp4'; 
	
	var filePath="D:\\vedio\\"+deviceId + '_' + channelNum +".mp4";  playStartTime, playEndTime */
	var nOperateType = 0;
    var Offset = 0;
    var code = IScanClientOCXCtrl.CX_DownLoadVideoFile(filePath, playStartTime, playEndTime, deviceId, nOperateType, channelNum, Offset);      
	if(code == 0){
		alert("操作成功，开始下载！");
	}else{
		alert("下载录像失败！");
	}
	$("#btnVideoDown").unbind("click");
	$("#btnVideoDown").bind("click",stopDownloadVedioFile);
	$("#btnVideoDown").html("停止");
	$("#btnStopVideoDownload").css("display","inline-block");
	
	intsetInterval=window.setInterval("showDownloadByTime();", 2000);
	
}

//停止下载
function stopDownloadVedioFile(){
	$("#btnVideoDown").unbind("click");
	$("#btnVideoDown").bind("click",DownloadByTime);
	$("#btnVideoDown").html("下载");
	 window.clearInterval(intsetInterval);
      var code = IScanClientOCXCtrl.CX_StopDownVideoFile(deviceId);    
      if(code == 0){
							alert("停止下载成功！");
					}else{
						  alert("停止下载失败！");
					}
      $("#btnStopVideoDownload").css("display","none");
}


function showDownloadByTime(){
	var nPos=IScanClientOCXCtrl.CX_GetDownLoadPos(deviceId);
	if(nPos==100){
		 window.clearInterval(intsetInterval);
		 stopDownloadVedioFile();
	}
	$("#downbar").css("width",nPos+"%")
//	alert("当前下载进度  "+nPos+"% !");
}

function addData(shift) {
    var hourstr=now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
    var minutestr=now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
    var secondstr=now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();
    nowstr = [hourstr, minutestr, secondstr].join(':');
    date.push(nowstr);
    data.push(parseFloat(Math.random() * 30+50).toFixed(1));

    if (shift) {
        date.shift();
        data.shift();
    }

    now = new Date(+new Date(now) + oneDay);
}




	
//打开新窗体
function openWindow(url){
	var openLink = $("#txtOpenWindow");
	openLink.attr('href', url);
	openLink[0].click();
}

function changeVechile(){
	if(isinitselect){
		isinitselect=false;
	}else{

			try{
				exitstopplay();
			}catch(e){
				
			}
			
			var vid=$("#selectVehicleSel").val();
			openWindow(appCtx + "/video/hisVideo.html?vehicleID="+vid);

		
	}
}

function downLoadVideo(){
	
}

function setVideo(){
	$('#myModal').modal('show');
}

function closeVideo(){
	$('#myModal').modal('hide');
}

/**
 * 获取今天之前的日期
 * @param day
 */
function getDay(day){
	var today = new Date(); 
	return getCalcuDay(today,day);
}
/**
 * 获取指定日期的前几天
 * @param today
 * @param day
 * @returns {String}
 */
function getCalcuDay(today,day){
    var targetday_milliseconds=today.getTime() - 1000*60*60*24*day;          

    today.setTime(targetday_milliseconds); //注意，这行是关键代码    
      
    var tYear = today.getFullYear();  
    var tMonth = today.getMonth();  
    var tDate = today.getDate();  
    var tHuors= today.getHours();
    var tMinutes= today.getMinutes();
    var tSeconds= today.getSeconds();
    
    tMonth = doHandleMonth(tMonth + 1);  
    tDate = doHandleMonth(tDate);  
    tHuors = doHandleMonth(tHuors);  
    tMinutes = doHandleMonth(tMinutes);  
    tSeconds = doHandleMonth(tSeconds); 
    return tYear+"-"+tMonth+"-"+tDate+" "+tHuors+":"+tMinutes+":"+tSeconds;  
} 
function doHandleMonth(month){  
    var m = month;  
    if(month.toString().length == 1){  
       m = "0" + month;  
    }  
    return m;  
} 

var loadXML = function(xmlString){
    var xmlDoc=null;
    //判断浏览器的类型
    //支持IE浏览器 
    if(!window.DOMParser && window.ActiveXObject){   //window.DOMParser 判断是否是非ie浏览器
        var xmlDomVersions = ['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
        for(var i=0;i<xmlDomVersions.length;i++){
            try{
                xmlDoc = new ActiveXObject(xmlDomVersions[i]);
                xmlDoc.async = false;
                xmlDoc.loadXML(xmlString); //loadXML方法载入xml字符串
                break;
            }catch(e){
            }
        }
    }
    //支持Mozilla浏览器
    else if(window.DOMParser && document.implementation && document.implementation.createDocument){
        try{
            /* DOMParser 对象解析 XML 文本并返回一个 XML Document 对象。
             * 要使用 DOMParser，使用不带参数的构造函数来实例化它，然后调用其 parseFromString() 方法
             * parseFromString(text, contentType) 参数text:要解析的 XML 标记 参数contentType文本的内容类型
             * 可能是 "text/xml" 、"application/xml" 或 "application/xhtml+xml" 中的一个。注意，不支持 "text/html"。
             */
            domParser = new  DOMParser();
            xmlDoc = domParser.parseFromString(xmlString, 'text/xml');
        }catch(e){  
        }
    }
    else{
        return null;
    }

    return xmlDoc;
}

function changeBackSelect(){
	var keyname=$("#videoBack").val();
	var objVideo=videoCache.get(keyname);
	
	playStartTime=objVideo.startTime;
	playEndTime=objVideo.stopTime;
}


function queryVehicleTrack(){
	 var paramsGrid = [{
         name : 'vehicleID',
         value : vehicleID
     },{
         name : 'startTime',
         value : playStartTime.substring(0,4)+"-"+playStartTime.substring(4,6)+"-"+playStartTime.substring(6,8)+" "+playStartTime.substring(8,10)+":"+playStartTime.substring(10,12)+":"+playStartTime.substring(12,14)
     },{
         name : 'endTime',
         value : playEndTime.substring(0,4)+"-"+playEndTime.substring(4,6)+"-"+playEndTime.substring(6,8)+" "+playEndTime.substring(8,10)+":"+playEndTime.substring(10,12)+":"+playEndTime.substring(12,14)
     },{
         name : 'registrationNO',
         value : regNO
     },{
         name : 'internal_number',
         value : internal_number
     }];
  
 	
 	$("#trackList").flexOptions({
		url : appCtx + "/video/queryVideoVehicleTrackListForGrid.html",
		newp : 1,// 设置起始页
 		params : paramsGrid
 	}).flexReload();// 重新加载  
 	
 
}

</script>
</body>
</html>
